# coding:utf-8

"""
Author: roguesir
Date: 2017/8/30
GitHub: https://roguesir.github.com
Blog: http://blog.csdn.net/roguesir
"""

import numpy as np
import matplotlib.pyplot as plt
import cmath

x1 = 48
x2 = 260
x3 = (x2-x1)/2 + x1
y3 = 10
a = y3 / ((x3-x1)*(x3-x2))

def sgn(value):
    if value < 48:
        return 0
    elif value < 260:
        return a*(value-x1)*(value-x2);
    else:
        return 0


plt.figure(figsize=(8, 4))
x = np.linspace(0, 280, 280)
y = np.array([])
for v in x:
    y = np.append(y, np.linspace(sgn(v), sgn(v), 1))

plt.plot(x, y, 'b', label='评分函数')
plt.xlabel('停留时长(秒)')
plt.ylabel('浏览评分')
plt.legend()
plt.show()